<extend name="Base/common"/>
<block name="header">
    <title>{$meta_title}</title>
</block>
<block name="body">
    <img style="padding-left:5px;padding-top: 5px" onclick="history.go(-1)"  width="40px" src="__MAST_HOME__/picture/return.png">
    <a href="{:U('User/material')}">
        <img style="position: absolute;right: 5px;top: 5px" width="35px" src="__MAST_HOME__/picture/shouye.png">
    </a>
    <div class="col-xs-12" style="margin-top: 15px;padding: 0 15px 20px;">
        <div class="col-xs-12 EditData">
            <div class="">
                手机<i class="Important">&ensp;*</i>
            </div>
            <input id="Tel" class=" form-control " type="text"  value="{$data.phone}"  />
            <div class="">
                密码<i class="Important">&ensp;*</i>
            </div>
            <input id="Pass" class=" form-control " type="password"    />
            <div class="">
                昵称<i class="Important">&ensp;*</i>
            </div>
            <input readonly id="UserRealName" class=" form-control " type="text"  value="{$data.nickname}"  />
            <div class="">
                性别
            </div>
            <select id="sex" class="col-xs-12 form-control " >
                <option value="1" <if condition="$dat.sex==1"> selected="selected" </if>>男</option>
                <option value="2" <if condition="$dat.sex==2"> selected="selected" </if>>女</option>
            </select>
            <div class="">
                开户银行<i class="Important">&ensp;*</i>
            </div>
            <input id="BankName" class=" form-control " type="text" name="bank" value="{$data.bank}"   />
            <div class="">
                银行卡号<i class="Important">&ensp;*</i>
            </div>
            <input id="BankNum" class=" form-control " type="text" name="bank_no" value="{$data.bank_no}"   />
            <div class="">
                真实姓名<i class="Important">&ensp;*</i>
            </div>
            <if condition="$data.realname">
                <input    readonly class=" form-control " type="text" name="realname" value="{$data.realname}" />
                <else/>
                <input id="UserName"  readonly   class=" form-control " type="text" name="realname" value="{$data.realname}" />
            </if>
            <div class="">
                身份证号码<i class="Important">&ensp;*</i>
            </div>
            <if condition="$data.card">
                <input  readonly  class=" form-control "  type="text" name="IdCard"  value="{$data.card}" />
                <else/>
                <input id="IdCard"   class=" form-control " name="IdCard" type="text"  value="{$data.card}" />
            </if>
            <div class="">
                所在地区
            </div>
            <div class="col-xs-6" style="padding-left: 0;margin:0">
                <select id="sheng" class="col-xs-12" name="province1" onchange="sh1()"></select>
                <input id="Province" name="Province" type="hidden">
            </div>
            <div class="col-xs-6" style="padding-right: 0;margin:0">
                <select id="shi" class="col-xs-12" name="city1" onchange="shi1()"></select>
                <input id="City" name="City" type="hidden">
            </div>
            <div class="">
                详细地址<i class="Important">&ensp;*</i>
            </div>
            <input id="Town" class=" form-control " type="text" value="{$data.detailed}" />
        </div>
        <div class="col-xs-12 submit">
            <a id="hide" class="col-xs-12 text-center hide alert alert-danger" style="padding: 5px;">保存成功</a>
            <a onclick="sub()" class="col-xs-12 btn btn-info sub">提交保存</a>
        </div>
    </div>
</block>

<!--<block name="side"></block>-->
<block name="script">
    <script>
        // localStorage.UId ='72B47CE4BB09BCD6';
        GetUserInfo();
        initLocation({
            sheng_val : "",
            shi_val : "",
        });
        //省份以及市区地址选择
        function sh1() {
            $("#Province").val($("#sheng").find("option:selected").text());
        }
        function shi1() {
            $("#City").val($("#shi").find("option:selected").text())
        }
        //个人信息验证
        function sub() {
            var URegex = /^1[34578][0-9]{9}$/;
            var User = $("#Tel").val();
            if (URegex.test(User) != true) {
//                $("#hide").removeClass('hide');
//                $("#hide").html('手机号码错误');
//                timer();
                layer.msg('手机号码错误');
                return false;
            }
            if ($("#UserRealName").val() == "" || $("#UserRealName").val() == null || $("#Tel").val() == "" || $("#BankName").val() == "" || $("#BankNum").val() == "" || $("#UserName").val() == "" || $("#Pass").val() == "") {
//                $("#hide").removeClass('hide');
//                $("#hide").html('输入不能为空');
                layer.msg('数据不能为空');
                timer();
                return false
            } else {
                $.post("{:U('User/saverial')}", {
                    UId : localStorage.UId,
                    Tel : $("#Tel").val(), //手机
                    UserPass : $("#Pass").val(), //密码
                    UserRealName : $("#UserRealName").val(), //昵称
                    Sex : $("#sex").val(), //性别
                    Email : $("#Email").val(), //邮箱
                    BankName : $("#BankName").val(), //开户银行
                    BankNum : $("#BankNum").val(), //银行卡号
//                    UserName : $("#UserName").val(), //开户姓名realname
                    UserName : $("input[name='realname']").val(), //开户姓名
                    Province : $("#Province").val(), //省
                    City: $("#City").val(),//市区
                    Town: $("#Town").val(),
//                    IdCard:$("#IdCard").val(),//身份证
                    IdCard:$("input[name='IdCard']").val(),//身份证
                }, function(ret) {
                    if (ret) {
                        if (ret.state == "1") {
                            var str = ret.msg;
//                            $("#hide").removeClass('hide');
//                            $("#hide").html('保存成功');
                            layer.msg(ret.info);
                            timer();
//                            location.href = "usercenter.html";
                            location.href = "{:U('User/index')}";
                        }else if(ret=="1"){
                            layer.msg('手机号码格式有误');
                            return false
                        }  else if(ret=="2"){
                           layer.msg('银行卡账号格式有误');
                            return false
                        } else if(ret=="3"){
                            layer.msg('身份证号码格式有误');
                            return false
                        }else {
//                            $("#hide").removeClass('hide');
//                            $("#hide").html(ret.info);
                            layer.msg(ret.info);
                            timer();
                        }
                    } else {
                        $("#hide").removeClass('hide');
                        $("#hide").html('网络错误');
                    }
                })
            }
        }
        //提示信息显示时间
        function timer() {
            setTimeout(function() {
                $("#hide").addClass('hide');
            }, 2000)
        }
        function GetUserInfo() {
            $.post("", {
                        UId: localStorage.UId
                    },
                    function (ret) {
                        // alert(JSON.stringify(ret));
                        if (ret.state == "1") {
                            var data = ret.msg;
                            $("#Tel").val(data.Tel);
                            $("#UserRealName").val(data.UserRealName);
                            $("#BankName").val(data.BankName);
                            $("#BankNum").val(data.BankNum);
                            $("#UserName").val(data.UserName);
                            $("#Province").val(data.Province);
                            $("#City").val(data.City);
                            $("#IdCard").val(data.IdCard);
                            if (data.UserName=='' || data.UserName==null ) {
                                $("#UserName").removeAttr("readonly");
                            }
                            if (data.IdCard=='' || data.IdCard==null ) {
                                $("#IdCard").removeAttr("readonly");
                            }
                            if (data.UserRealName=='' || data.UserRealName==null ) {
                                $("#UserRealName").removeAttr("readonly");
                            }
                        }
                    });
        }
    </script>
</block>